<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

 class Insert extends CI_Controller
 {
	    function __construct()
	  {
		   //membuat construktor;
		   parent::__construct();
		   //meload helper form dan url
		   $this->load->helper(array('form','url'));
		   // membuat object model
		   $this->load->model('m_insert');
	  }
	  
	  
	  function index()
	  {
		$this->load->view('form.php');// loading form view
		$productname = $_POST['productname'];
	  }
	  
	  function insert_to_db()
		{
			//check kosong & data error
			if($this->input->post('productname') == ""){
				$data['errorinsert'] = "1";
				$this->load->view('home',$data); 
			}
			else if($this->input->post('saleprice') == "") {
				$data['errorinsert'] = "2";
				$this->load->view('home',$data); 
			}
			else if($this->input->post('purchaseprice') == "") {
				$data['errorinsert'] = "3";
				$this->load->view('home',$data); 
			}
			else if($this->input->post('description') == "") {
				$data['errorinsert'] = "4";
				$this->load->view('home',$data); 
			}
			else if($this->input->post('image') == "") {
				$data['errorinsert'] = "5";
				$this->load->view('home',$data); 
			}
			else{
				//kirim ke model
				$this->m_insert->insert_into_db();
			}
			
		}

		
 }
?>